package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.service.AdminFeedbackService;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;


public class AdminFeedbackServiceImpl implements AdminFeedbackService {

    @Override
    public List<MarketFeedback> list(String id, String username, String phoneNumber, String feedback, String page, String time, String limit) {

        //根据反馈名和反馈ID进行模糊查询

        SqlSession sqlSession = MybatisUtils.getSession();

        MarketFeedbackMapper feedbackMapper = sqlSession.getMapper(MarketFeedbackMapper.class);

        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();

        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();

        if (id != null&& username==null){
            criteria.andContentLike("%" + id + "%");
        }
        if (username != null&& id==null){
            criteria.andContentLike("%" + username + "%");
        }
        if (username !=null&& id != null){
            criteria.andContentLike("%" + username + "%");
            criteria.andContentLike("%" + id + "%");
        }

        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<MarketFeedback> marketFeedbacks = feedbackMapper.selectByExample(marketFeedbackExample);

        return marketFeedbacks;


    }
}
